package com.george.common.api.feign.fallBack.stock;

import com.george.common.api.feign.stock.StockServiceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Create By George on /2023/4/10
 * description: 订单Feign服务降级实现
 *
 * @author George
 */
@Slf4j
@Component
public class StockServiceFeignFallBack implements FallbackFactory<StockServiceFeign> {

    /**
     * Returns an instance of the fallback appropriate for the given cause
     */
    @Override
    public StockServiceFeign create(Throwable cause) {
        return new StockServiceFeign(){

            /**
             * 根据订单生成出库单
             *
             * @param orderId
             * @return void
             * @author George
             * @date 2023/4/10 1:14
             */
            @Override
            public String outStock(String orderId) {
                log.error("StockServiceFeign: createOrder fail reason was: {}", cause.getMessage());
                return "根据订单生成出库单失败，库存服务接口降级返回";
            }
        };
    }
}
